package com.pys.beans;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;
import javax.faces.model.SelectItem;

import com.pys.common.beans.BaseBean;
import com.pys.pojo.PysKullanici;
import com.pys.pojo.PysProje;
import com.pys.pojo.PysTalep;
import com.pys.pojo.PysTalepDurum;
import com.pys.pojo.PysTalepOncelik;
import com.pys.pojo.PysTalepTip;
import com.pys.service.KullaniciService;
import com.pys.service.OncelikService;
import com.pys.service.ProjeService;
import com.pys.service.TalepDurumService;
import com.pys.service.TalepTipService;
import com.pys.utils.FacesUtils;

@ManagedBean
@ViewScoped
public class TalepDetayBean extends BaseBean implements Serializable {
	private PysTalep talep;

	private List<SelectItem> projes;
	private Long projeId;
	private List<SelectItem> kullanicis;
	private Long atananKullaniciId;
	private Long olusturanKullaniciId;
	private List<SelectItem> talepTips;
	private Long talepTipId;
	private List<SelectItem> talepOnceliks;
	private Long talepOncelikId;
	private List<SelectItem> talepDurums;
	private Long talepDurumId;
	private String ozet;
	private String tanim;
	private String dosya;
	private int isDegeri;
	private Date teslimTarih;
	private boolean durum = true;
	private String keyword;

	private PysTalep selectedTalep;
	private List<PysTalep> list;

	public TalepDetayBean() {
		talep = (PysTalep) FacesUtils.getFlash().get("selectedTalep");
		if (talep != null) {
			projeId = talep.getPysProje().getId();
			ProjeService projeService = new ProjeService();
			List<PysProje> pysProjes = projeService.getAllAktifList();
			projes = new ArrayList<SelectItem>();
			for (PysProje pysProje : pysProjes) {
				projes.add(new SelectItem(pysProje.getId(), pysProje.getAd()));
			}

			atananKullaniciId = talep.getPysKullaniciByAtananKullaniciId()
					.getId();
			KullaniciService kullaniciService = new KullaniciService();
			List<PysKullanici> pysKullanicis = kullaniciService
					.getAllAktifList();
			kullanicis = new ArrayList<SelectItem>();
			for (PysKullanici pysKullanici : pysKullanicis) {
				kullanicis.add(new SelectItem(pysKullanici.getId(),
						pysKullanici.getAd() + " " + pysKullanici.getSoyad()));
			}

			talepTipId = talep.getPysTalepTip().getId();
			TalepTipService talepTipService = new TalepTipService();
			List<PysTalepTip> pysTalepTips = talepTipService.getAllAktifList();
			talepTips = new ArrayList<SelectItem>();
			for (PysTalepTip pysTalepTip : pysTalepTips) {
				talepTips.add(new SelectItem(pysTalepTip.getId(), pysTalepTip
						.getAd()));
			}

			talepOncelikId = talep.getPysTalepOncelik().getId();
			OncelikService oncelikService = new OncelikService();
			List<PysTalepOncelik> pysOnceliks = oncelikService
					.getAllAktifList();
			talepOnceliks = new ArrayList<SelectItem>();
			for (PysTalepOncelik pysOncelik : pysOnceliks) {
				talepOnceliks.add(new SelectItem(pysOncelik.getId(), pysOncelik
						.getAd()));
			}

			if (talep.getPysTalepDurum() != null)
				talepDurumId = talep.getPysTalepDurum().getId();
			TalepDurumService talepDurumService = new TalepDurumService();
			List<PysTalepDurum> pysTalepDurums = talepDurumService
					.getAllAktifList();
			talepDurums = new ArrayList<SelectItem>();
			for (PysTalepDurum pysTalepDurum : pysTalepDurums) {
				talepDurums.add(new SelectItem(pysTalepDurum.getId(),
						pysTalepDurum.getAd()));
			}
		}
	}

	/*
	 * ACTIONS
	 */
	public void refreshList() {
		// RoleService roleService = new RoleService();
		// list = roleService.getAllList();
	}

	public void saveAction() {
		// RoleService roleService = new RoleService();
		// if (selectedRole == null) {
		// PysRole pysRole = new PysRole();
		// pysRole.setAd(ad);
		// roleService.save(pysRole);
		// } else {
		// selectedRole.setAd(ad);
		// roleService.update(selectedRole);
		// }
		// refreshList();
		// clear();
	}

	public void deleteAction() {
		// RoleService roleService = new RoleService();
		// roleService.delete(selectedRole);
		// refreshList();
		// clear();
	}

	public void updateAction() {
		// ad = selectedRole.getAd();
	}

	public void clear() {
		// selectedRole = null;
		// ad = null;
	}

	/*
	 * GETTER-SETTER
	 */

	public PysTalep getTalep() {
		return talep;
	}

	public void setTalep(PysTalep talep) {
		this.talep = talep;
	}

	public List<SelectItem> getProjes() {
		return projes;
	}

	public void setProjes(List<SelectItem> projes) {
		this.projes = projes;
	}

	public Long getProjeId() {
		return projeId;
	}

	public void setProjeId(Long projeId) {
		this.projeId = projeId;
	}

	public List<SelectItem> getKullanicis() {
		return kullanicis;
	}

	public void setKullanicis(List<SelectItem> kullanicis) {
		this.kullanicis = kullanicis;
	}

	public Long getAtananKullaniciId() {
		return atananKullaniciId;
	}

	public void setAtananKullaniciId(Long atananKullaniciId) {
		this.atananKullaniciId = atananKullaniciId;
	}

	public Long getOlusturanKullaniciId() {
		return olusturanKullaniciId;
	}

	public void setOlusturanKullaniciId(Long olusturanKullaniciId) {
		this.olusturanKullaniciId = olusturanKullaniciId;
	}

	public List<SelectItem> getTalepTips() {
		return talepTips;
	}

	public void setTalepTips(List<SelectItem> talepTips) {
		this.talepTips = talepTips;
	}

	public Long getTalepTipId() {
		return talepTipId;
	}

	public void setTalepTipId(Long talepTipId) {
		this.talepTipId = talepTipId;
	}

	public List<SelectItem> getTalepOnceliks() {
		return talepOnceliks;
	}

	public void setTalepOnceliks(List<SelectItem> talepOnceliks) {
		this.talepOnceliks = talepOnceliks;
	}

	public Long getTalepOncelikId() {
		return talepOncelikId;
	}

	public void setTalepOncelikId(Long talepOncelikId) {
		this.talepOncelikId = talepOncelikId;
	}

	public String getOzet() {
		return ozet;
	}

	public void setOzet(String ozet) {
		this.ozet = ozet;
	}

	public String getTanim() {
		return tanim;
	}

	public void setTanim(String tanim) {
		this.tanim = tanim;
	}

	public String getDosya() {
		return dosya;
	}

	public void setDosya(String dosya) {
		this.dosya = dosya;
	}

	public int getIsDegeri() {
		return isDegeri;
	}

	public void setIsDegeri(int isDegeri) {
		this.isDegeri = isDegeri;
	}

	public Date getTeslimTarih() {
		return teslimTarih;
	}

	public void setTeslimTarih(Date teslimTarih) {
		this.teslimTarih = teslimTarih;
	}

	public boolean isDurum() {
		return durum;
	}

	public void setDurum(boolean durum) {
		this.durum = durum;
	}

	public String getKeyword() {
		return keyword;
	}

	public void setKeyword(String keyword) {
		this.keyword = keyword;
	}

	public PysTalep getSelectedTalep() {
		return selectedTalep;
	}

	public void setSelectedTalep(PysTalep selectedTalep) {
		this.selectedTalep = selectedTalep;
	}

	public List<PysTalep> getList() {
		return list;
	}

	public void setList(List<PysTalep> list) {
		this.list = list;
	}

	public List<SelectItem> getTalepDurums() {
		return talepDurums;
	}

	public void setTalepDurums(List<SelectItem> talepDurums) {
		this.talepDurums = talepDurums;
	}

	public Long getTalepDurumId() {
		return talepDurumId;
	}

	public void setTalepDurumId(Long talepDurumId) {
		this.talepDurumId = talepDurumId;
	}

}
